package com.snow.core.exception.handler;

import com.snow.lib.exception.BaseException;
import com.snow.lib.result.ResultUtil;
import com.snow.lib.result.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * 拦截异常
 * Created by GongWenHua on 2017/8/4.
 */
@ControllerAdvice
@Slf4j
public class BaseExceptionHandler {
    /**
     * 处理BaseException
     *
     * @param e
     * @return
     */
    @ExceptionHandler({BaseException.class, MissingServletRequestParameterException.class})
    public ResultVO handleBaseException(BaseException e) {
        log.error("[异常] [{}]", e.getMessage(), e);
        return ResultUtil.error(e);
    }
}
